What is @statsig/client-core?
@statsig/client-core is a JavaScript library designed to help developers implement feature flags, dynamic configurations, and A/B testing in their applications. It allows for real-time feature management and experimentation, enabling teams to release features safely and measure their impact.
What are @statsig/client-core's main functionalities?
Feature Flags
This code demonstrates how to use @statsig/client-core to check if a feature flag is enabled for a specific user. The `checkGate` method is used to determine the status of a feature flag.
const { StatsigClient } = require('@statsig/client-core');
async function main() {
const client = new StatsigClient('client-api-key', { userID: 'user123' });
await client.initializeAsync();
const isFeatureEnabled = client.checkGate('new_feature');
console.log('Is new feature enabled:', isFeatureEnabled);
}
main();
Dynamic Configurations
This code shows how to retrieve dynamic configurations using @statsig/client-core. The `getConfig` method fetches configuration values that can be used to customize application behavior without deploying new code.
const { StatsigClient } = require('@statsig/client-core');
async function main() {
const client = new StatsigClient('client-api-key', { userID: 'user123' });
await client.initializeAsync();
const config = client.getConfig('button_color');
console.log('Button color config:', config.getValue('color', 'defaultColor'));
}
main();
A/B Testing
This example illustrates how to use @statsig/client-core for A/B testing. The `getExperiment` method is used to determine which variant of an experiment a user is assigned to, allowing for controlled testing of different features or configurations.
const { StatsigClient } = require('@statsig/client-core');
async function main() {
const client = new StatsigClient('client-api-key', { userID: 'user123' });
await client.initializeAsync();
const experiment = client.getExperiment('button_test');
console.log('Experiment variant:', experiment.getValue('variant', 'control'));
}
main();
Other packages similar to @statsig/client-core
launchdarkly-js-client-sdk
LaunchDarkly is a feature management platform that provides similar functionality to @statsig/client-core, including feature flags, A/B testing, and dynamic configurations. It offers a robust set of tools for managing feature releases and experiments, with a focus on scalability and integration with various platforms.
unleash-client
Unleash is an open-source feature management solution that provides feature toggling capabilities similar to @statsig/client-core. It focuses on simplicity and flexibility, allowing developers to manage feature flags and experiments with ease. Unleash is a good alternative for teams looking for an open-source solution.